#include <iostream>
using namespace std;
#define int long long
signed main()
{
	int a,b,c;//a^b%c
	cin>>a>>b>>c; 
	int tempa=a,tempb=b;
	a%=c;
	int ret=1;
	while(b)
	{
		if(b&1)
		{
			b--;
			ret=a*ret%c;
		}
		else
		{
			b>>=1;
			a=a*a%c;
		}
	}
	cout<<tempa<<'^'<<tempb<<" mod "<<c<<'='<<ret<<endl;
	return 0;
 } 
